package org.liuhy.jbpm4
{
	import flash.events.MouseEvent;
	
	import mx.containers.VBox;
	import mx.controls.Image;
	import mx.core.DragSource;
	import mx.managers.DragManager;
	
	import org.liuhy.control.BorderImage;
	//控件工具箱;
	public class JbpmToolBox extends VBox
	{
		public function JbpmToolBox()
		{
			initTools();
		}
		public function initTools():void{
			this.createTools("line");
			this.createTools("decision");
			this.createTools("task");
			this.createTools("start");
			this.createTools("end");
		}
		private function createTools(p_id:String):void{
			
			var _img:BorderImage = new BorderImage();
			_img.id = p_id;
//			_img.width = 80;
//			_img.height= 60;
			_img.setStyle("borderWidth","0");
			_img.setStyle("borderColor","0x000000");
			_img.source = "images/"+ p_id + ".png";
			this.addChild(_img);
			_img.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
			_img.addEventListener(MouseEvent.MOUSE_DOWN,onToolMouseDown);
			
		}
		public function onToolMouseDown(event:MouseEvent):void{				
			var _img:Image = Image(event.currentTarget);
			_img.stage.focus = _img;
			_img.setStyle("borderThickness","0");				
		}
		public function onMouseMove(event:MouseEvent):void{
			var dragInitiator:Image = Image(event.currentTarget);
            var ds:DragSource = new DragSource();
            ds.addData(this,"img");
            DragManager.doDrag(dragInitiator, ds, event);
		}
	}
}